//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    isShow:true,
    game: {
      roomNo: '',
      common_name: '',
      special_name: '',
      game_number:''
    },
    res:""
  },
  onReady: function () {
    // this.Modal = this.selectComponent(".getcard");
    // this.Modal.showModal();
  },
  //开始按钮
  start: function (e) {
    let data = this.data.game
    var that = this
    this.setData({
      game:{
        roomNo: this.data.game.roomNo,
        common_name: this.data.game.common_name,
        special_name: this.data.game.special_name,
        game_number: parseInt(this.data.game.game_number)
      }
    })
    if (this.data.game.game_number > 8 || this.data.game.game_number < 5) {
      wx.showToast({
        title: '游戏人数为5-8人'
      })
    }
    else{
      wx.request({
        url: 'http://192.168.0.104:8080/referee_poker',
        method: 'post',
        data,
        // header:{
        //   "Content-Type": "json"
        // },
        success: function (res) {
          that.data.res = JSON.stringify(res.data.data)
          console.log(that.data.res)
          wx.navigateTo({
            url: '../caipan1/caipan1?resData=' + that.data.res
          })
        }
      })
    }
  },
  // 返回按钮
  back:function(){
    wx.navigateTo({
      url:"../index/index"
    })
  },
  // 房间号
  roomno:function(e){
    // console.log(e)
    var roomNo = e.detail.value
    this.setData({
      game:{
        roomNo: roomNo,
        common_name: '',
        special_name: '',
        game_number:''
      }
    })
    // console.log(this.data.game.roomNo)
  },
  // 游戏人数
  getNumber(e){
    // console.log(e)
    var game_number = e.detail.value
    this.setData({
      game:{
        roomNo: this.data.game.roomNo,
        common_name: '',
        special_name: '',
        game_number: game_number
      }
    })
    if (game_number > 8 || game_number<5){
      wx.showToast({
        title: '游戏人数为5-8人'
      })
    }
  },
  // 平民词语
  getPopulace:function(e){
    var common_name = e.detail.value
    this.setData({
      game: {
        roomNo: this.data.game.roomNo,
        common_name: common_name,
        special_name: '',
        game_number: this.data.game.game_number
      }
    })
  },
  // 卧底词语
  getUndercover: function (e) {
    var special_name = e.detail.value
    this.setData({
      game: {
        roomNo: this.data.game.roomNo,
        common_name: this.data.game.common_name,
        special_name: special_name ,
        game_number: this.data.game.game_number
      }
    })
  },
  // 点击自定义的时候
  customize:function(){
    this.setData({
      isShow:!this.data.isShow
    })
  }
})
